local hx__qiangxi = fk.CreateSkill {
  name = "hx__qiangxi",
  tags = { Skill.Switch },
}

hx__qiangxi:addEffect("active", {
  anim_type = "switch",
  card_num = 1,
  target_num = 1,
  prompt = function(self, player)
		if player:getSwitchSkillState(hx__qiangxi.name, false) == fk.SwitchYang then
      return "#hx__qiangxi-yang"
    else
      return "#hx__qiangxi-yin"
    end
  end,
  can_use = function(self, player)
    local equipCards = table.filter(player:getCardIds("he"), function(id)
      return Fk:getCardById(id).type == Card.TypeEquip
    end)
    return #equipCards > 0 and player:usedSkillTimes(hx__qiangxi.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, player, to_select, selected)
    return Fk:getCardById(to_select).type == Card.TypeEquip and not player:prohibitDiscard(to_select)
  end,
  target_filter = function(self, player, to_select, selected, selected_cards)
    if #selected == 0 and to_select ~= player then
      if #selected_cards == 0 or table.contains(player:getCardIds("e"), selected_cards[1]) then
        return player:inMyAttackRange(to_select)
      else
        return player:distanceTo(to_select) == 1
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    if player:getSwitchSkillState(hx__qiangxi.name, true) == fk.SwitchYang then
      local another = table.filter(room:getOtherPlayers(player), function(p) return p ~= target end)
      if #effect.cards > 0 then
        room:loseHp(player, 1, hx__qiangxi.name)
        room:throwCard(effect.cards, hx__qiangxi.name, player)
        room:damage{
          from = player,
          to = target,
          damage = 1,
          skillName = hx__qiangxi.name,
        }
        if #another > 0 then
          local target2 = room:askToChoosePlayers(player, {
            targets = another,
            min_num = 1,
            max_num = 1,
            prompt = "#hx__qiangxi-yang-choose",
            skill_name = hx__qiangxi.name,
            cancelable = false,
          })
          if #target2 > 0 then
            room:damage{
              from = player,
              to = target2[1],
              damage = 1,
              skillName = hx__qiangxi.name,
            }
          end
        end
      end
    else
      if #effect.cards > 0 then
        room:loseHp(player, 1, self.name)
        room:throwCard(effect.cards, self.name, player)
        room:damage{
          from = player,
          to = target,
          damage = 2,
          skillName = hx__qiangxi.name,
        }
      end
    end
  end,
})



return hx__qiangxi